package cn.gxufe.reliable.message.admin.config;

import cn.gxufe.reliable.message.admin.lock.ClusterElectionManager;
import cn.gxufe.reliable.message.admin.utils.PublishUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yingjie.rong
 **/
@Configuration
public class AdminConfig {

    @Bean
    public PublishUtils publishUtils(){
        return PublishUtils.getPublishUtils();
    }

    @Bean
    public ClusterElectionManager clusterElectionManager(@Value("${spring.election.open: true}") String open){
        return new ClusterElectionManager(StringUtils.equalsIgnoreCase(open.trim() , "true"));
    }

}
